home *** CD-ROM | disk | FTP | other *** search
Wrap
var wo; function ISRILoptions() { this.gVKNames = []; this.offlineListView = 1; } ISRILoptions.prototype = { _init : function() { try { Components.utils.import("resource://rilglobals/ISRILglobals.js"); // -- Connect to main RIL Objects -- // var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); wo = wm.getMostRecentWindow("navigator:browser"); if (!wo.ISRIL) { wo = ISRILglobals.mainWindow; ISRIL.d('no wo'); if (!wo.ISRIL) { ISRIL.d('no wo'); wo = ( (!window.opener.opener) ? (window.opener):(window.opener.opener) ); } } ISRIL = wo.ISRIL; ISRILprefs = wo.ISRILprefs; ISRILsync = wo.ISRILsync; ISRILajax = wo.ISRILajax; // --- Populate Folder Menu --- // ISRIL.loadFolder(); ISRILoptions.PopulateFolder( ISRIL.GetAllFolders() ); try { ISRILoptions.PopulateFolder( ISRIL.GetAllFolders(ISRIL.sBookmarks.toolbarFolder), ISRIL.sBookmarks.getItemTitle( wo.PlacesUtils.toolbarFolderId ) + '-> ' ); } catch(err) {} ISRILxul.bip('folder').selectedItem = ISRILxul.bip('folder-'+ISRILglobals.folderId); // --- Load Options --- // //Reading ISRILxul.bip('mark').selectedItem = ISRILxul.bip('mark-' + ISRILprefs.pref('mark') ); ISRILxul.bip('read').selectedItem = ISRILxul.bip('read-' + ISRILprefs.pref('read') ); ISRILxul.bip('open').selectedItem = ISRILxul.bip('open-' + ISRILprefs.pref('open') ); ISRILxul.bip('autoMarkItems').checked = ISRILprefs.prefB('autoMark'); //Saving ISRILxul.bip('closeTab').checked = ISRILprefs.prefB('auto-close-tab'); ISRILxul.bip('link-checks').selectedItem = ISRILxul.bip('link-checks-' + ISRILprefs.pref('link-checks') ); ISRILxul.bip('AutoTags').value = ISRILprefs.pref('auto-tags'); //Appearance ISRILoptions.checkPageTotal(); ISRIL.d( ISRILxul.bip('list-page').selectedIndex ); ISRILxul.bip('list-view').selectedIndex = (ISRILprefs.pref('list-view')=='normal')?0:1; ISRILxul.bip('list-place').selectedItem = ISRILxul.bip('list-place-' + ISRILprefs.pref('list-place') ); ISRILxul.bip('list-type').selectedItem = ISRILxul.bip('list-type-' + ISRILprefs.pref('list-type') ); ISRILoptions.togglePages(); ISRILxul.bip('list-page').selectedIndex = 9; ISRILxul.bip('ShowClickToSave').checked = ISRILprefs.prefB('clicktosaveinbar'); ISRILxul.bip('ShowUnreadCount').checked = ISRILprefs.prefB('show-count'); ISRILxul.bip('context-menu').checked = ISRILprefs.prefB('context-menu'); ISRILxul.bip('force-styles').checked = ISRILprefs.prefB('force-styles'); //Offline ISRILxul.bip('AutoOffline').checked = ISRILprefs.prefB('autoOffline'); //Shortcuts var listitems = ISRILxul.bip('ks').getElementsByTagName('listitem'); var id; var keySet; for(i in listitems) { if (listitems[i].id) { id = listitems[i].id.replace(ISRILxul.dPrefix + 'ks-',''); keySet = ISRILprefs.pref('hotkey_'+id).split('||'); listitems[i].value = ISRILprefs.pref('hotkey_'+id); ISRILxul.bi(listitems[i].id + '-v').setAttribute('label', keySet[0] + ' + ' + keySet[1] ); } } //Syncing ISRILsync.GetAFeed(); //Online Access ISRILxul.bip('feed').checked = ISRILprefs.prefB('feed'); ISRILxul.bip('sync').checked = ISRILprefs.prefB('sync'); ISRILxul.bip('feed-private').checked = ISRILprefs.prefB('feed-private'); ISRILoptions.CheckOnlineSettings(); //Google Reader ISRILxul.bip('integrate-gr').checked = ISRILprefs.prefB('integrate-gr'); // -- Get Keysets -- // for (var property in KeyEvent) { ISRILoptions.gVKNames[KeyEvent[property]] = property.replace("DOM_",""); } ISRILoptions.gVKNames[8] = "VK_BACK"; ISRILoffline._init(); //Select Tab ISRILoptions.selectTab( null , ((window.arguments && window.arguments[0])?(window.arguments[0]):('workflow')) ); } catch(err) { window.close(); alert('Error loading options: ' + err); } }, selectTab : function(obj, value) { value = ((obj)?(obj.value):(value)); if (this.lastTab != value) { if (this.lastTab) { ISRILxul.bip('opts-' + this.lastTab ).className = ISRILxul.bip('opts-' + value ).className; } ISRILxul.bip('options-menu').selectedItem = ISRILxul.bip('options-menu-'+value); ISRILxul.bip('opts-' + value ).className += ' ' + ISRILxul.dPrefix + 'open'; //onopen function if (ISRILoptions['func_'+value]) { ISRILoptions['func_'+value](); } this.lastTab = value; } }, PopulateFolder : function(folders, prefix) { prefix = ( (!prefix) ? (''):(prefix) ); var i; var folder; for(i in folders) { folder = folders[i].node; ISRILxul.bip('folderItems').appendChild( ISRILxul.createNode('menuitem', {label:prefix+folder.title,id:ISRILxul.dPrefix+'folder-'+folder.itemId,value:folder.itemId}) ); if (folders[i].subs) { ISRILoptions.PopulateFolder(folders[i].subs, prefix+'-> '); } } }, // --- // SelectKey : function(event) { ISRILxul.bip("newKey").disabled = false; ISRILxul.bip("setKey").disabled = false; ISRILxul.bip('newKey').focus(); }, DetectKey : function(event) { event.preventDefault(); event.stopPropagation(); var modifiers = []; if(event.altKey) modifiers.push("alt"); if(event.ctrlKey) modifiers.push("control"); if(event.metaKey) modifiers.push("meta"); if(event.shiftKey) modifiers.push("shift"); modifiers = modifiers.join(" "); var key = ""; var keycode = ""; if(event.charCode) key = String.fromCharCode(event.charCode).toUpperCase(); else { keycode = ISRILoptions.gVKNames[event.keyCode]; if(!keycode) return;} ISRILoptions.lastKeySet = modifiers+'||'+((key)?(key):(keycode)); ISRILxul.bip('newKey').value = ISRIL.formatKey( modifiers, key, keycode ); }, SetKey : function(event) { if (ISRILoptions.lastKeySet && ISRILxul.bip('ks').selectedItem) { ISRILxul.bip('ks').selectedItem.value = ISRILoptions.lastKeySet; ISRILxul.bi( ISRILxul.bip('ks').selectedItem.id + '-v' ).setAttribute('label' , ISRILxul.bip('newKey').value ); } }, // -- Appearance -- // func_appearance : function() { ISRILoptions.checkPageTotal(); }, checkPageTotal : function() { var maxRows = ISRILxul.maxPageN( ISRILxul.bip('list-view').selectedItem.value ); var n = ISRILxul.bip('list-page').value; var current = ISRILprefs.pref('list-page') * 1; ISRILxul.bip('list-page-msg').value = ''; ISRILxul.fillSelect( ISRILxul.bip('list-page'), 4, maxRows, current<=maxRows?current:maxRows ); ISRILxul.bip('list-page-msg').value = ISRILxul.bip('list-view').selectedItem.value == 'normal' ? ISRIL.l('pageNswitch') : ''; }, togglePages : function() { ISRILxul.bip('list-page').disabled = (ISRILxul.bip('list-type').selectedIndex == 0)?false:true; }, // -- Offline Options -- // func_offline : function() { ISRILoptions.offlinePopList(); }, offlinePopList : function() { l = ISRIL.GetList(11); ISRILoptions.checkList = new Object(); ISRILxul.ClearMenu( ISRILxul.bip('offlineList-rows') ); var n = 0; for(i in l) { nsURI = ISRIL.uri(l[i].uri); var rowClass = ''; var disabled = false; var hidden = false; if (!ISRILoffline.getF(l[i].itemId).exists()) { rowClass += ISRILxul.dPrefix+'not-saved-offline'; disabled = true; hidden = true; } else { n++; } var row = ISRILxul.createNode('row', {class:rowClass,hidden:hidden} ); var chkbox = ISRILxul.createNode('checkbox', {id:ISRILxul.dPrefix+'ol_r_'+l[i].itemId,disabled:disabled}); var title = ISRILxul.createNode('label', {value:((l[i].title.length > 0)?(l[i].title):(nsURI.host)), tooltiptext:l[i].title, style:"background-image:url('"+ISRIL.sIcon.getFaviconImageForPage(nsURI).spec+"')"}); row.appendChild(chkbox); row.appendChild(title); ISRILxul.bip('offlineList-rows').appendChild(row); ISRILoptions.checkList[i] = {chkbox:chkbox, id:l[i].itemId, row:row}; } if (n == 0) { var row = ISRILxul.createNode('row', {class:'isRitL-dim'} ); var title = ISRILxul.createNode('label', {value:ISRIL.l('NoOfflineItems')}); row.appendChild(title); ISRILxul.bip('offlineList-rows').appendChild(row); } }, offlineToggleUncached : function(btn) { ISRILoptions.offlineListView *= -1; for(i in ISRILoptions.checkList) { if (ISRILoptions.checkList[i].row.className == ISRILxul.dPrefix + 'not-saved-offline') { ISRILoptions.checkList[i].row.hidden = ( (ISRILoptions.offlineListView==1) ? (true):(false) ); } } btn.label = ((ISRILoptions.offlineListView==1)?ISRIL.l('ShowUncached'):ISRIL.l('HideUncached')); }, offlineSelectAll : function() { for(i in ISRILoptions.checkList) { if (!ISRILoptions.checkList[i].row.className) { ISRILoptions.checkList[i].chkbox.checked = true; } } }, offlineRemoveSelected : function() { if (ISRILprefs.prefB('prompt_clear_offline')) { var check = {value: false}; var result = ISRIL.sPrompts.confirmCheck(window, ISRIL.l('OfflineTitle'), ISRIL.l('DeleteCache'), ISRIL.l('DoNotAskAgain'), check); ISRILprefs.setPref('prompt_clear_offline', !check.value); } else { var result = true; } if (result) { var c = 0; for(i in ISRILoptions.checkList) { if (ISRILoptions.checkList[i].chkbox.checked) { ISRILoffline.deleteOffline( ISRILoptions.checkList[i].id ); c++; } } ISRILoptions.offlinePopList(); if (c == 0) { ISRILxul.sPrompt.alert(window, ISRIL.l('ReadItLater'), ISRIL.l('NothingSelected') ); } } }, // --- Syncing --- // CheckSyncPrivacy : function() { if (!ISRILoptions.CheckedServer) { var ajax = new ISRILajax(); var params = ISRILsync.lin(); ajax.post(ISRILsync.apiURL + 'user', ISRILoptions.CheckSyncPrivacyCallback, params); } }, CheckSyncPrivacyCallback : function(r) { var data = ISRIL.json.decode(r); ISRILxul.bip('feed-private').checked = data.feed_protected==1?true:false; ISRILprefs.setPref('feed-private', data.feed_protected==1?true:false); ISRILprefs.setPref('feed-email-saved', data.email==1?true:false); ISRILoptions.CheckedServer = true; }, CheckOnlineSettings : function() { if (ISRILxul.bip('feed').checked) { //Online Access on ISRILoptions.CheckSyncPrivacy(); ISRILxul.bip('online-off').hidden = true; ISRILoptions.DisableGroup('sync', false); ISRILxul.bip('feed-private').disabled = false; if (ISRILxul.bip('sync').checked) { ISRILoptions.SyncSetupStep( ISRILprefs.prefB('sync')?3:0 ); ISRILoptions.DisableGroup('sync-setup', false); } else { ISRILoptions.SyncSetupStep(0); ISRILoptions.DisableGroup('sync-setup', true); } } else { ISRILxul.bip('sync').checked = false; ISRILxul.bip('online-off').hidden = false; ISRILxul.bip('feed-private').disabled = true; ISRILoptions.SyncSetupStep(0); ISRILoptions.DisableGroup('sync', true); ISRILoptions.DisableGroup('sync-setup', true); } }, DisableGroup : function(g,disabled) { var group = ISRILxul.bip('group-'+g); group.className = ((!disabled)?(''):('isRitL-dim')); t = new Array('checkbox', 'radiogroup', 'textbox', 'button'); for(i=0; i<t.length; i++) { ins = group.getElementsByTagName(t[i]); for(ii=0; ii<ins.length; ii++) { ins[ii].disabled = disabled; } } }, SyncSetupStep : function(step) { ISRILxul.bip('sync-step-0').hidden = (step==0)?false:true; ISRILxul.bip('sync-step-1').hidden = (step==1)?false:true; ISRILxul.bip('sync-step-2').hidden = (step==2)?false:true; ISRILxul.bip('sync-step-3').hidden = (step==3)?false:true; if (step == 1) { //ISRILxul.bip('sync-what-default').hidden = ISRILprefs.pref('feed-which')=='alt'?false:true; } else if (step == 2) { switch(ISRILxul.bip('sync-what').selectedIndex) { case(0): ISRILoptions.SyncSetupStep(3); break; case(1): ISRILprefs.setPref('feed-which', 'default'); ISRILoptions.SyncSetupStep(3); break; } } else if (step == 3) { ISRILxul.bip('D-feed-id').value = ISRILsync.feedId(); ISRILxul.bip('D-sync-pass').value = ISRILsync.syncP(); ISRILxul.bip('SetToSync1').textContent = ISRIL.l('SetToSync1') + ' ' + ISRILsync.feedId() + '.'; ISRILxul.bip('SetToSync2').textContent = ISRIL.l('SetToSync2'); if (ISRILprefs.prefB('super-security-mode')) { ISRILxul.bip('D-sync-pass').type = 'password'; ISRILxul.bip('pass-hide').hidden = true; ISRILxul.bip('pass-retrieve').hidden = false; } else { ISRILxul.bip('D-sync-pass').type = ''; ISRILxul.bip('pass-hide').hidden = false; ISRILxul.bip('pass-retrieve').hidden = true; } } }, SaveFeed : function() { fId = ISRILxul.bip('L-feed-id').value; sPass = ISRILxul.bip('L-sync-pass').value; if (fId.length > 0 && sPass.length > 0) { ISRILsync.CheckLogin(fId, sPass, ISRILoptions.SaveFeedGo); } else { ISRILxul.sPrompt.alert(window, ISRIL.l('EnterSync'), ISRIL.l('EnterSyncError') ); } }, SaveFeedGo : function(r) { try { var data = ISRIL.json.decode(r); } catch(err) { return ISRILxul.sPrompt.alert(window, ISRIL.l('LoginFailed'), ISRIL.l('GeneralError') ); } if (data.msg) { return ISRILxul.sPrompt.alert(window, ISRIL.l('DetailsError'), data.msg ); } if (data.status == 1) { ISRILprefs.setPref('feed-which', 'alt'); ISRILprefs.setPref('feed-id-alt', ISRILxul.bip('L-feed-id').value); ISRILprefs.setPref('sync-alt', ISRILxul.bip('L-sync-pass').value); ISRILprefs.setPref('last_get', 0); ISRILxul.bip('L-feed-id').value = ''; ISRILxul.bip('L-sync-pass').value = ''; ISRILoptions.Accept(); ISRILoptions.CheckOnlineSettings(); } else { ISRILxul.sPrompt.alert(window, ISRIL.l('DetailsError'), ISRIL.l('DetailsErrorMsg') ); } }, HidePass : function(email, invalidEmail) { if (!ISRILprefs.prefB('feed-email-saved')) { var input = {value: email?email:ISRIL.l('YourEmail')}; if ( ISRILxul.sPrompt.prompt(window, ISRIL.l('ReadItLater'), ISRIL.l('GetEmail') + (invalidEmail ? ("\n\n" + ISRIL.l('InvalidEmail')) : ''), input, null, {}) ) { if (input.value.match(/([A-Za-z0-9\-_\.\+])+@([A-Za-z0-9\-_\+])+.([A-Za-z0-9\-_\+])+/)) { var a = new ISRILajax(); var params = ISRILsync.lin() + '&email=' + input.value; a.post(ISRILsync.apiURL + 'user-set-email',ISRILoptions.SetEmailCallback, params); ISRILxul.bip('pass-hide').label = ISRIL.l('SavingEmail') + '...'; } else { ISRILoptions.HidePass(input.value, true); } } return false; } else { ISRILprefs.setPref('super-security-mode', true); ISRILxul.bip('D-sync-pass').type = 'password'; ISRILxul.bip('pass-hide').hidden = true; ISRILxul.bip('pass-retrieve').hidden = false; } }, SetEmailCallback : function(r) { try { var data = ISRIL.json.decode(r); } catch(err) { return ISRILxul.sPrompt.alert(window, ISRIL.l('ReadItLater'), ISRIL.l('GeneralError') ); } if (data.msg) { return ISRILxul.sPrompt.alert(window, ISRIL.l('DetailsError'), data.msg ); } if (data.status == 1) { ISRILprefs.setPref('feed-email-saved', true); ISRILoptions.HidePass(); } else { ISRILxul.sPrompt.alert(window, ISRIL.l('DetailsError'), ISRIL.l('DetailsErrorMsg') ); } }, RetrievePass : function() { ISRIL.GoTo('http://readitlaterlist.com/forgot', false, 'window'); }, ChangePassword : function() { ISRIL.GoTo('http://readitlaterlist.com/pass', false, 'window'); }, ToggleFeedPassword : function() { if (ISRILxul.bip('feed-private').checked) { ISRILxul.sPrompt.alert(window, ISRIL.l('ReadItLater'), ISRIL.l('NotePasswordFeed') ); } if (ISRILprefs.prefB('feed-private') != ISRILxul.bip('feed-private').checked) { ISRIL.ajax = new ISRILajax(); var params = ISRILsync.lin() + '&feed_protected=' + (ISRILxul.bip('feed-private').checked?1:0); ISRIL.ajax.post(ISRILsync.apiURL + 'feed-private',ISRILoptions.ToggleFeedPasswordCallback, params); return false; } }, ToggleFeedPasswordCallback : function(r) { var data = ISRIL.json.decode(r); if (data.status == 1) { ISRILprefs.setPref('feed-private', data.setAs==1?true:false); } }, DeleteOnlineList : function() { if ( ISRILxul.sPrompt.confirm(window, ISRIL.l('ReadItLater'), ISRIL.l('ClearAccountPrompt') + "\n\n" + ISRIL.l('GoThereNow') ) ) { ISRIL.GoTo('readitlaterlist.com/privacy_clear/', null, 'window'); } return false; }, /* --- */ checkedTxt : function(o) { return ( (o.checked) ? ('true'):('false') ); }, Accept : function() { try { //General //Reading ISRILprefs.setPref('read', ISRILxul.bip('read').selectedItem.value ); ISRILprefs.setPref('mark', ISRILxul.bip('mark').selectedItem.value ); ISRILprefs.setPref('open', ISRILxul.bip('open').selectedItem.value ); ISRILprefs.setPref('autoMark', ISRILxul.bip('autoMarkItems').checked ); //Saving ISRILprefs.setPref('auto-close-tab', ISRILxul.bip('closeTab').checked ); ISRILprefs.setPref('link-checks', ISRILxul.bip('link-checks').selectedItem.value ); if (ISRILxul.bip('folder').selectedItem.value != ISRILprefs.pref('folderId') ) { ISRIL.saveNewFolder( ISRILxul.bip('folder').selectedItem.value ); } ISRILprefs.setPref('auto-tags', ISRILxul.bip('AutoTags').value ); //Keyboard Shortcuts var listitems = ISRILxul.bip('ks').getElementsByTagName('listitem'); var id; var keySet; for(i in listitems) { if (listitems[i].id) { id = listitems[i].id.replace(ISRILxul.dPrefix + 'ks-',''); ISRILprefs.setPref('hotkey_'+id, listitems[i].value, true); } } ISRIL.SetupKeyStrokes(); //not being called from wo (or not available) //Appearance PerPage = ISRILxul.bip('list-page').selectedIndex + ISRILxul.bip('list-page').getAttribute('min') * 1; ISRILprefs.setPref('list-view', ISRILxul.bip('list-view').selectedItem.value ); ISRILprefs.setPref('list-place', ISRILxul.bip('list-place').selectedItem.value ); ISRILprefs.setPref('list-type', ISRILxul.bip('list-type').selectedItem.value ); ISRILprefs.setPref('list-page', PerPage >= 4 ? PerPage : 4 ); //Buttons ISRILprefs.setPref('context-menu', ISRILxul.bip('context-menu').checked ); ISRILprefs.setPref('force-styles', ISRILxul.bip('force-styles').checked ); ISRILprefs.setPref('clicktosaveinbar', ISRILxul.bip('ShowClickToSave').checked ); ISRILprefs.setPref('show-count', ISRILxul.bip('ShowUnreadCount').checked ); wo.ISRILxul.UseClickToSaveStatusBar(); wo.ISRILxul.ShowCount(true); //Offline ISRILprefs.setPref('autoOffline', ISRILxul.bip('AutoOffline').checked ); //Google Reader ISRILprefs.setPref('integrate-gr', ISRILxul.bip('integrate-gr').checked ); //Syncing if (!ISRILprefs.prefB('feed') && ISRILxul.bip('feed').checked ) { ISRILprefs.setPref('feed', ISRILxul.bip('feed').checked); ISRILsync.getUpdatesStart(true); } else { ISRILprefs.setPref('feed', ISRILxul.bip('feed').checked); } ISRILprefs.setPref('sync', ISRILxul.bip('sync').checked); ISRIL.checkPage(); ISRILsync.GetAFeed(); if (wo.document.getElementById('sidebar').contentWindow.location.href == "chrome://isreaditlater/content/isreaditlaterlist.xul") { wo.ISRILxul.bi('sidebar').contentWindow.ISRILxul.OpenReadingList(); } return true; } catch(err) { alert('Error saving options: ' + err); } }, Cancel : function() { return true; }, } var ISRILoptions = new ISRILoptions();